package com.atguigu.hellomp.test;

import io.minio.BucketExistsArgs;
import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.UploadObjectArgs;
import io.minio.errors.*;
import org.joda.time.DateTime;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

public class T1 {
    public static void main(String[] args) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        MinioClient minioClient = MinioClient.builder()
                .endpoint("http://192.168.171.100:9000")
                .credentials("minioadmin", "minioadmin")
                .build();
        BucketExistsArgs builder = BucketExistsArgs.builder()
                .bucket("lease")
                .build();
        boolean b = minioClient.bucketExists(builder);
        System.out.println("是否存在这个"+b);

        String fileName = "123.jpg";
        String filenameExtension = StringUtils.getFilenameExtension(fileName);
        String uuid = UUID.randomUUID().toString().replace("-", "");
        String uuidExtension = uuid + "." + filenameExtension;
        String date = new DateTime().toString("yyyy/MM/dd/");
        String bucketName = "lease";
        UploadObjectArgs builder1 = UploadObjectArgs.builder()
                .bucket(bucketName)
                .object(date+uuidExtension)
                .filename("C:/Users/20631/Desktop/水果.png")
                .build();
        ObjectWriteResponse objectWriteResponse = minioClient.uploadObject(builder1);
        String url = "http://192.168.171.100:9000/"+bucketName+"/"+date+uuidExtension ;
        System.out.println(url);
    }
}
